//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using OpenLS.Chart.UI.Internals;

namespace OpenLS.Chart.UI
{
    class CountAndGroupingToZAxisInfoConverter : IMultiValueConverter
    {
        #region IMultiValueConverter Members

        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values[0] == DependencyProperty.UnsetValue)
                return new AxisInfo(-1, 0, -1, 0);
            int count = (int)values[0];
            BarGrouping grouping;
            if (values[1] is Grouping)
            {
                switch ((Grouping)values[1])
                {
                    case Grouping.PercentStacked:
                        grouping = BarGrouping.PercentStacked;
                        break;
                    case Grouping.Stacked:
                        grouping = BarGrouping.Stacked;
                        break;
                    case Grouping.Standard:
                        grouping = BarGrouping.Stacked;
                        break;
                    default: throw new NotSupportedException();
                }
            }
            else if (values[1] is BarGrouping)
            {
                grouping = (BarGrouping)values[1];
            }
            else
                throw new NotSupportedException();
            switch (grouping)
            {
                case BarGrouping.Clustered:
                case BarGrouping.PercentStacked:
                case BarGrouping.Stacked:
                    double dbl1 = -1;
                    return new AxisInfo(dbl1, 0, dbl1, 0);
                case BarGrouping.Standard:
                    double dbl2 = -count;
                    return new AxisInfo(dbl2, 0, dbl2, 0);
                default: throw new NotSupportedException();
            }
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion
    }
}